<template>
  <div class="control-box">
    <div class="control-col">
      <div class="silder-box">
        <div class="silder-hd">
          <div class="silder-hd-title">外壳透明度</div>
          <div class="silder-hd-value">{{ silderValue }}%</div>
        </div>
        <div class="silder-bd">
          <a-slider
            v-model:value="silderValue"
            @afterChange="hooks.useHandleTransparent"
          />
        </div>
      </div>
    </div>
    <div class="control-col">
      <div class="switch-box">
        <div
          class="switch-item"
          v-for="(item, index) in switchList"
          :key="index"
        >
          <div class="switch-label">{{ item.name }}</div>
          <a-switch
            v-model:checked="item.checked"
            @change="handleChageSwitch($event, item.type)"
          />
        </div>
      </div>
    </div>
    <div class="control-col">
      <div class="choose-box">
        <div class="choose-title">组件选择</div>
        <div class="choose-content">
          <div
            class="choose-item"
            :class="{ cur: item.checked }"
            v-for="(item, index) in components"
            :key="index"
            @click="handleChangeTab(index)"
          >
            {{ item.name }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { ref } from "vue";
import * as hooks from "@/hooks/useTest2Hooks";
//透明度滑块
const silderValue = ref(40);
//开关列表
const switchList = ref([
  {
    name: "动画演示",
    checked: false,
    type: 1,
  },
  {
    name: "光学特效",
    checked: true,
    type: 2,
  },
]);
const handleChageSwitch = (checked: boolean, type: number) => {
  console.log(checked, type);
  if (type == 1) {
    hooks.useHandleAnimation(checked);
  }
  if (type == 2) {
    hooks.useHandleOptical(checked);
  }
};
//组件选择
const components = ref([
  {
    name: "光栅",
    checked: false,
  },
  {
    name: "反射镜",
    checked: false,
  },
  {
    name: "狭缝",
    checked: false,
  },
  {
    name: "探测器",
    checked: false,
  },
]);
const checkedArr: any = ref([]);
const handleChangeTab = (index: number) => {
  if (checkedArr.value.indexOf(index) != -1) {
    checkedArr.value.splice(checkedArr.value.indexOf(index), 1);
    components.value[index].checked = false;
  } else {
    checkedArr.value.push(index);
    components.value[index].checked = true;
  }
  console.log(checkedArr.value)
  hooks.useHandleComponent(checkedArr.value.join(","));
};
</script>
<style lang="less" scoped>
.control-box {
  padding: 0 12px;
  .control-col {
    border-bottom: 1px solid #e8e9ed;
    &:last-child {
      border-bottom: none;
    }
  }
  .silder-box {
    padding: 12px 0;
    .silder-hd {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .silder-hd-title {
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 14px;
        color: #262626;
        line-height: 20px;
      }
      .silder-hd-value {
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 14px;
        color: #262626;
        line-height: 20px;
      }
    }
    .silder-bd {
      :deep(.ant-slider-track) {
        background-color: #2776ff;
      }
      :deep(.ant-slider-handle::after) {
        box-shadow: 0 0 0 2px #2776ff;
      }
    }
  }
  .switch-box {
    padding: 8px 0;
    .switch-item {
      padding: 8px 0;
      display: flex;
      align-items: center;
      justify-content: space-between;
    }
  }
  .choose-box {
    padding: 16px 0;
    .choose-title {
      font-family: PingFangSC, PingFang SC;
      font-weight: 400;
      font-size: 14px;
      color: #262626;
      line-height: 20px;
      text-align: left;
      font-style: normal;
      margin-bottom: 12px;
    }
    .choose-content {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 12px;
      .choose-item {
        width: 136px;
        height: 40px;
        background: #ffffff;
        border-radius: 4px;
        border: 1px solid #e6ebf1;
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 14px;
        color: #262626;
        line-height: 40px;
        text-align: center;
        font-style: normal;
        cursor: pointer;
        &.cur {
          background: rgba(39, 118, 255, 0.1);
          border: 1px solid #2776ff;
          color: #2776ff;
        }
      }
    }
  }
}
</style>
